package com.blockchain.console.servlets.trading;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.EntrustType;
import com.blockchain.common.enums.JyztStatus;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.JyfqEntity;
import com.blockchain.console.service.trading.entity.JyglEntity;
import com.blockchain.console.service.trading.query.TradingQuery;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.query.Paging;
import com.blockchain.framework.service.query.PagingResult;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;
import com.blockchain.util.parser.TimestampParser;

@Right(id = "C_TRADING_LIST", isMenu = true, name = "委托管理")
public class WtList extends AbstractTradingServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		processPost(request, response, serviceSession);
	}

	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		JyfqEntity[] jyfqs=tsradingManage.jyfqSearch();
		PagingResult<JyglEntity> tsradings = tsradingManage.tradingSearch(new TradingQuery() {

			@Override
			public EntrustType getWtzt() {
				return EnumParser.parse(EntrustType.class, request.getParameter("wtzt"));
			}

			@Override
			public String getUsername() {
				return request.getParameter("userName");
			}
			@Override
			public JyztStatus getJyztStatus() {
				return EnumParser.parse(JyztStatus.class, request.getParameter("jylx"));
			}

			@Override
			public int getId() {
				return IntegerParser.parse(request.getParameter("id"));
			}

			@Override
			public Timestamp getCreateTimeStart() {
				return TimestampParser.parse(request.getParameter("start"));
			}

			@Override
			public Timestamp getCreateTimeEnd() {
				return TimestampParser.parse(request.getParameter("end"));
			}

			@Override
			public String getBuyer() {
				return null;
			}

			@Override
			public String getSeller() {
				return null;
			}

			@Override
			public int getXsts() {
				// TODO Auto-generated method stub
				return 0;
			}
		}, new Paging() {

			@Override
			public int getSize() {
				return 10;
			}

			@Override
			public int getCurrentPage() {
				return IntegerParser.parse(request.getParameter(PAGING_CURRENT));
			}
		});

		request.setAttribute("tsradings", tsradings);
		request.setAttribute("jyfqs", jyfqs);
		forwardView(request, response, getClass());
	}

}
